public class ActionTest{
    public static void main(String[] args) {
        // 匿名内部类实现：按"|"分割字符串
        Action splitByPipe = new Action() {
            @Override
            public String[] test(String str) {
                // "|"是正则特殊字符，需要用两个反斜杠转义
                return str.split("\\|");
            }
        };

        // 匿名内部类实现：按"-"分割字符串
        Action splitByHyphen = new Action() {
            @Override
            public String[] test(String str) {
                // "-"不是特殊字符，直接分割
                return str.split("-");
            }
        };

        // 测试按"|"分割
        String[] result1 = splitByPipe.test("a|b|c");
        System.out.println("按|分割结果：");
        for (String s : result1) {
            System.out.print("\"" + s + "\" ");
        }

        // 测试按"-"分割
        String[] result2 = splitByHyphen.test("a-b-c");
        System.out.println("\n按-分割结果：");
        for (String s : result2) {
            System.out.print("\"" + s + "\" ");
        }
    }
}
